import object_template from "./object_template.mjs";

let nodeNames = ["LI", "A"];
export default function menu_template({ container, template }) {
  console.log(template);
  let menu = document.createElement("menu");
  container.appendChild(menu);
  object_template(menu, template.menu);
  menu.addEventListener("click", (e) => {
    console.log(e);
    let menu = e.target.closest("menu");
    if (nodeNames.includes(e.target.nodeName)) {
      menu.querySelectorAll(".active").forEach((element) => {
        element.classList.remove("active");
      });
      e.target.classList.add("active");
    }
  });
  // object_template(container, template);
  // object_template(container, {
  //   ...template,
  //   ...{
  //     click: (e) => {
  //       console.log(e);
  //       let menu = e.sender;
  //       if (nodeNames.includes(e.event.srcElement.nodeName)) {
  //         menu.querySelectorAll(".active").forEach((element) => {
  //           element.classList.remove("active");
  //         });
  //         e.event.srcElement.classList.add("active");
  //       }
  //     },
  //   },
  // });
}
